package com.ewo.controller.ApplicationPageController;

import com.ewo.entity.ApplicationPage.CustomerEquipment;
import com.ewo.entity.ApplicationPage.CustomerInformation;
import com.ewo.entity.ApplicationPage.CustomerProject;
import com.ewo.entity.ResponseResult;
import com.ewo.service.ApplicationPage.CustomerEquipmentService;
import com.ewo.service.ApplicationPage.CustomerInformationService;
import com.ewo.service.ApplicationPage.CustomerProjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/equipment")
@CrossOrigin("*")
public class CustomerEquipmentController {

    @Resource
    CustomerProjectService customerProjectService;
    @Resource
    CustomerEquipmentService customerEquipmentService;
    @Resource
    CustomerInformationService customerInformationService;

    //查找所有设备信息
    @GetMapping("/allEquipment/{empId}")
    public ResponseResult findCustomerEquipmentByEmpId(@PathVariable int empId) {
        List<CustomerEquipment> customerEquipmentList = customerEquipmentService.findCustomerEquipmentByEmpId(empId);
        if (customerEquipmentList == null || customerEquipmentList.size() == 0) {
            return ResponseResult.fail();
        }
        return ResponseResult.ok(customerEquipmentList);
    }

    //根据客户id查找关联设备信息
    @GetMapping("/findOneEq/{cid}")
    public ResponseResult findCustomerEquipmentByEqId(@PathVariable int cid){
        //根据客户id查找客户信息
        CustomerInformation customerInformation = customerInformationService.findCustomerInformationByCid(cid);
        //根据客户id查找关联项目信息
        CustomerProject customerProject = customerProjectService.findCustomerProjectByCid(cid);
        //根据客户id查找关联设备信息
        CustomerEquipment customerEquipment = customerEquipmentService.findCustomerEquipmentByCid(cid);
        List<Object> objectList = new ArrayList<>();
        objectList.add(customerInformation);
        objectList.add(customerProject);
        objectList.add(customerEquipment);
        if (objectList == null || objectList.size()==0) {
            return ResponseResult.fail();
        }
        return ResponseResult.ok(objectList);
    }


}
